<?php
require_once sfConfig::get('sf_plugins_dir').'/tmcContactPlugin/lib/actions/tmcContactPluginActions.class.php';

class tmcContactActions extends tmcContactPluginActions
{
    public function executeContact(sfWebRequest $request)
    {
      $this->form = new tmcContactForm();
      unset($this->form['updated_at'], $this->form['modification_user_id']);

      if($request->isMethod('post')){
//        $this->form->bind($request->getParameter($this->form->getName()));

        $formValues = $request->getParameter($this->form->getName());

//        $captcha = array(
//            'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
//            'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
//          );
//
//        $formValues = array_merge( $formValues, array('captcha' => $captcha)  );

        $this->form->bind( $formValues );
        
        if ($this->form->isValid()){
          $this->object = $this->form->save();
          // e-mail
          $this->getMailer()->send(new tmcContactMailer($this->object));
          // redirect
          $this->getUser()->setFlash('object', $this->object);
          $this->redirect($this->generateUrl(sfConfig::get('app_tmcContactPlugin_redirect', 'tmc_contact_form'), true));
        }
      }

      isicsBreadcrumbs::getInstance()->addItem('Nous contacter', '#');

      $response = $this->getResponse();
      Utils::setSlogTitle('Nous contacter', $response);
    }
}
?>
